home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utildsk / hdsleep.lha / HDSleep / Source / gadtools.c < prev    next >
C/C++ Source or Header  |  1996-04-26  |  7KB  |  254 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Thom/Union
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include "gadtools.h"
  24.  
  25. struct Screen         *Scr = NULL;
  26. UBYTE                 *PubScreenName = NULL;
  27. APTR                   VisualInfo = NULL;
  28. struct Window         *MainWnd = NULL;
  29. struct Gadget         *MainGList = NULL;
  30. struct Menu           *MainMenus = NULL;
  31. struct Gadget         *MainGadgets[5];
  32. UWORD                  MainLeft = 202;
  33. UWORD                  MainTop = 72;
  34. UWORD                  MainWidth = 268;
  35. UWORD                  MainHeight = 72;
  36. UBYTE                 *MainWdt = (UBYTE *)"HDSleep v1.2";
  37. struct TextAttr       *Font, Attr;
  38. UWORD                  FontX, FontY;
  39. UWORD                  OffX, OffY;
  40.  
  41. struct IntuiText MainIText[] = {
  42.     1, 0, JAM2,133, 8, NULL, (UBYTE *)" Time To Go ", NULL };
  43.  
  44. #define Main_TNUM 1
  45.  
  46. struct NewMenu MainNewMenu[] = {
  47.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  48.     NM_ITEM, (STRPTR)"Sleep", (STRPTR)"S", 0, 0L, NULL,
  49.     NM_ITEM, (STRPTR)"Abort", (STRPTR)"A", 0, 0L, NULL,
  50.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  51.     NM_ITEM, (STRPTR)"About", (STRPTR)"B", 0, 0L, NULL,
  52.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  53.     NM_ITEM, (STRPTR)"Hide", (STRPTR)"H", 0, 0L, NULL,
  54.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, NULL,
  55.     NM_END, NULL, NULL, 0, 0L, NULL };
  56.  
  57. UWORD MainGTypes[] = {
  58.     NUMBER_KIND,
  59.     BUTTON_KIND,
  60.     BUTTON_KIND,
  61.     NUMBER_KIND,
  62.     BUTTON_KIND
  63. };
  64.  
  65. struct NewGadget MainNGad[] = {
  66.     147, 14, 45, 14, (UBYTE *)"Master:", NULL, GD_MASTEROFF, PLACETEXT_LEFT, NULL, NULL,
  67.     11, 51, 79, 15, (UBYTE *)"_Sleep", NULL, GD_SLEEP, PLACETEXT_IN, NULL, NULL,
  68.     94, 51, 79, 15, (UBYTE *)"_Abort", NULL, GD_ABORT, PLACETEXT_IN, NULL, NULL,
  69.     147, 27, 45, 14, (UBYTE *)"Slave:", NULL, GD_SLAVEOFF, PLACETEXT_LEFT, NULL, NULL,
  70.     177, 51, 79, 15, (UBYTE *)"_Quit", NULL, GD_QUIT, PLACETEXT_IN, NULL, NULL
  71. };
  72.  
  73. ULONG MainGTags[] = {
  74.     (TAG_DONE),
  75.     (GT_Underscore), '_', (TAG_DONE),
  76.     (GT_Underscore), '_', (TAG_DONE),
  77.     (TAG_DONE),
  78.     (GT_Underscore), '_', (TAG_DONE)
  79. };
  80.  
  81. static UWORD ComputeX( UWORD value )
  82. {
  83.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  84. }
  85.  
  86. static UWORD ComputeY( UWORD value )
  87. {
  88.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  89. }
  90.  
  91. static void ComputeFont( UWORD width, UWORD height )
  92. {
  93.     Font = &Attr;
  94.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  95.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  96.     FontX = Scr->RastPort.Font->tf_XSize;
  97.  
  98.     OffX = Scr->WBorLeft;
  99.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  100.  
  101.     if ( width && height ) {
  102.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  103.             goto UseTopaz;
  104.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  105.             goto UseTopaz;
  106.     }
  107.     return;
  108.  
  109. UseTopaz:
  110.     Font->ta_Name = (STRPTR)"topaz.font";
  111.     FontX = FontY = Font->ta_YSize = 8;
  112. }
  113.  
  114. int SetupScreen( void )
  115. {
  116.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  117.         return( 1L );
  118.  
  119.     ComputeFont( 0, 0 );
  120.  
  121.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  122.         return( 2L );
  123.  
  124.     return( 0L );
  125. }
  126.  
  127. void CloseDownScreen( void )
  128. {
  129.     if ( VisualInfo ) {
  130.         FreeVisualInfo( VisualInfo );
  131.         VisualInfo = NULL;
  132.     }
  133.  
  134.     if ( Scr        ) {
  135.         UnlockPubScreen( NULL, Scr );
  136.         Scr = NULL;
  137.     }
  138. }
  139.  
  140. void MainRender( void )
  141. {
  142.     struct IntuiText    it;
  143.     UWORD            cnt;
  144.  
  145.     ComputeFont( MainWidth, MainHeight );
  146.  
  147.     DrawBevelBox( MainWnd->RPort, OffX + ComputeX( 11 ),
  148.                     OffY + ComputeY( 7 ),
  149.                     ComputeX( 245 ),
  150.                     ComputeY( 40 ),
  151.                     GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  152.  
  153.     for ( cnt = 0; cnt < Main_TNUM; cnt++ ) {
  154.         CopyMem(( char * )&MainIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
  155.         it.ITextFont = Font;
  156.         it.LeftEdge  = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
  157.         it.TopEdge   = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
  158.         PrintIText( MainWnd->RPort, &it, 0, 0 );
  159.     }
  160. }
  161.  
  162. int OpenMainWindow( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     struct DrawInfo *DRI;
  167.     UWORD        lc, tc;
  168.     UWORD        wleft = MainLeft, wtop = MainTop, ww, wh;
  169.     ULONG Pen;
  170.  
  171.     ComputeFont( MainWidth, MainHeight );
  172.  
  173.     ww = ComputeX( MainWidth );
  174.     wh = ComputeY( MainHeight );
  175.  
  176.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  177.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  178.  
  179.     if ( ! ( g = CreateContext( &MainGList )))
  180.         return( 1L );
  181.  
  182.     for( lc = 0, tc = 0; lc < Main_CNT; lc++ ) {
  183.  
  184.         CopyMem((char * )&MainNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  185.  
  186.         ng.ng_VisualInfo = VisualInfo;
  187.         ng.ng_TextAttr   = Font;
  188.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  189.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  190.         ng.ng_Width      = ComputeX( ng.ng_Width );
  191.         ng.ng_Height     = ComputeY( ng.ng_Height);
  192.  
  193.         MainGadgets[ lc ] = g = CreateGadgetA((ULONG)MainGTypes[ lc ], g, &ng, ( struct TagItem * )&MainGTags[ tc ] );
  194.  
  195.         while( MainGTags[ tc ] ) tc += 2;
  196.         tc++;
  197.  
  198.         if ( NOT g )
  199.             return( 2L );
  200.     }
  201.  
  202.     if(DRI=GetScreenDrawInfo(Scr))
  203.     {
  204.         Pen=DRI->dri_Pens[BARDETAILPEN];
  205.         FreeScreenDrawInfo(Scr,DRI);
  206.     }
  207.     else Pen=1;
  208.  
  209.     if ( ! ( MainMenus = CreateMenus( MainNewMenu, GTMN_NewLookMenus, TRUE, GTMN_FrontPen, Pen, TAG_DONE )))
  210.         return( 3L );
  211.  
  212.     LayoutMenus( MainMenus, VisualInfo, TAG_DONE );
  213.  
  214.     if ( ! ( MainWnd = OpenWindowTags( NULL,
  215.                 WA_Left,    wleft,
  216.                 WA_Top,        wtop,
  217.                 WA_Width,    ww + OffX + Scr->WBorRight,
  218.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  219.                 WA_IDCMP,    NUMBERIDCMP|BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  220.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_NEWLOOKMENUS,
  221.                 WA_Gadgets,    MainGList,
  222.                 WA_Title,    MainWdt,
  223.                 WA_ScreenTitle,    "HDSleep v1.2 - by Tomasz Muszynski (Thom/Union)",
  224.                 WA_PubScreen,    Scr,
  225.                 TAG_DONE )))
  226.     return( 4L );
  227.  
  228.     SetMenuStrip( MainWnd, MainMenus );
  229.     GT_RefreshWindow( MainWnd, NULL );
  230.  
  231.     MainRender();
  232.  
  233.     return( 0L );
  234. }
  235.  
  236. void CloseMainWindow( void )
  237. {
  238.     if ( MainMenus      ) {
  239.         ClearMenuStrip( MainWnd );
  240.         FreeMenus( MainMenus );
  241.         MainMenus = NULL;    }
  242.  
  243.     if ( MainWnd        ) {
  244.         CloseWindow( MainWnd );
  245.         MainWnd = NULL;
  246.     }
  247.  
  248.     if ( MainGList      ) {
  249.         FreeGadgets( MainGList );
  250.         MainGList = NULL;
  251.     }
  252. }
  253.  
  254.